
********************************************************************************
* Global GLP-1 eligibilty													   *
* By: Felix Teufel 														   	   *
* Last updated: 8 Jan 2025									  				   *
********************************************************************************

** Define paths **
global data "[insert_path]/Data"												// insert path to data files
global results "[insert_path]/Results"											// insert path to results folder			

********************************************************************************
***							 MAIN ANALYSES									 ***						
********************************************************************************

*** FIGURE 2: Main results ***

** Eligibility by country-level characteristics **		

use "$data/glp1_final.dta", clear
cd "$data"

svyset psu_num[pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  		
putexcel set Fig2_MainA.xlsx, sheet(Country-level) replace

* Global *
svy, subpop(analytic_pop_all): proportion glp1_elig_Asia
matrix est = e(b)
putexcel E2 = matrix(est[1, 2]*100)
matrix ci = r(table)'
putexcel F2 = matrix(ci[2, 5..6]*100)
count if analytic_pop_all == 1 & glp1_elig_Asia == 1
putexcel C2 = `r(N)'
count if analytic_pop_all == 1
putexcel D2 = `r(N)'

* Country-income group *
svy, subpop(analytic_pop_all) over(countryGDPclass): proportion glp1_elig_Asia
matrix est = e(b)'
putexcel E4 = matrix(est[5..8, 1]*100)
matrix ci = r(table)'
putexcel F4 = matrix(ci[5..8, 5..6]*100)
forval x = 1/4 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & countryGDPclass == `x'
putexcel C`=3+`x'' = `r(N)'
count if analytic_pop_all == 1 & countryGDPclass == `x'
putexcel D`=3+`x'' = `r(N)'
}

* Region *
svy, subpop(analytic_pop_all) over(worldregion7): proportion glp1_elig_Asia
matrix est = e(b)'
putexcel E9 = matrix(est[8..14, 1]*100)
matrix ci = r(table)'
putexcel F9 = matrix(ci[8..14, 5..6]*100)
forval x = 1/7 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & worldregion7 == `x'
putexcel C`=8+`x'' = `r(N)'
count if analytic_pop_all == 1 & worldregion7 == `x'
putexcel D`=8+`x'' = `r(N)'
}

** Eligibility by individual-level characteristics **		

use "$data/glp1_final.dta", clear
svyset psu_num[pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  		
putexcel set Fig2_mainB.xlsx, sheet(Individual-level) modify

* Sex *			
svy, subpop(analytic_pop_all) over(sex): proportion glp1_elig_Asia
matrix est = e(b)'
putexcel E3 = matrix(est[3..4, 1]*100)
matrix ci = r(table)'
putexcel F3 = matrix(ci[3..4, 5..6]*100)
forval x = 0/1 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & sex == `x'
putexcel C`=3+`x'' = `r(N)'
count if analytic_pop_all == 1 & sex == `x'
putexcel D`=3+`x'' = `r(N)'
}

* Age group *
preserve
drop if mi(age) & analytic_pop_all == 1					// 9 obs dropped
svy, subpop(analytic_pop_all) over(age_cat): proportion glp1_elig_Asia
matrix est = e(b)'
putexcel E6 = matrix(est[5..8, 1]*100)
matrix ci = r(table)'
putexcel F6 = matrix(ci[5..8, 5..6]*100)
forval x = 1/4 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & age_cat == `x'
putexcel C`=5+`x'' = `r(N)'
count if analytic_pop_all == 1 & age_cat == `x'
putexcel D`=5+`x'' = `r(N)'
}
restore 

* Education *
preserve
*bys country: mdesc educat3 if analytic_pop_all == 1	 	// Tokelau missing educat3
drop if country == "Tokelau"									// 554 obs dropped
drop if mi(educat3) & analytic_pop_all == 1						// 2,379 obs dropped
svy, subpop(analytic_pop_all) over(educat3): proportion glp1_elig_Asia
matrix est = e(b)'
putexcel E11 = matrix(est[4..6, 1]*100)
matrix ci = r(table)'
putexcel F11 = matrix(ci[4..6, 5..6]*100)
forval x = 0/2 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & educat3 == `x'
putexcel C`=11+`x'' = `r(N)'
count if analytic_pop_all == 1 & educat3 == `x'
putexcel D`=11+`x'' = `r(N)'
}
restore

* Wealth quintiles *																		
preserve
*bys country: mdesc wealth_quintile  		// 22 countries missing wealth_quintiles (see next lines)
drop if country == "Bangladesh" | country == "Barbados" | country == "Belarus" | country == "Burkina Faso" | country == "Costa Rica" ///
| country == "Czech Republic" | country == "El Salvador" | country == "England" | country == "Iraq" | country == "Libya" ///
| country == "Malawi" | country == "Malta" | country == "Nepal" | country == "Nigeria" | country == "Pakistan" ///
| country == "Qatar" | country == "Spain" | country == "Tokelau" | country == "Turkmenistan" | country == "USA"  ///
| country == "Venezuela" | country == "Wallis and Futuna" 		
drop if mi(wealth_quintile) & analytic_pop_all == 1					// 26,261 obs dropped in 78 remaining survys (=77 countries)			
svy, subpop(analytic_pop_all) over(wealth_quintile): proportion glp1_elig_Asia
matrix est = e(b)'
putexcel E15 = matrix(est[6..10, 1]*100)
matrix ci = r(table)'
putexcel F15 = matrix(ci[6..10, 5..6]*100)
forval x = 1/5 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & wealth_quintile == `x'
putexcel C`=14+`x'' = `r(N)'
count if analytic_pop_all == 1 & wealth_quintile == `x'
putexcel D`=14+`x'' = `r(N)'
}
restore


*** FIGURE 3: Bubble plot *** 		// Same data used for World Map

use "$data/glp1_final.dta", clear
cd "$data"
putexcel set Fig3_bubble.xlsx, sheet(wpop) replace

svy, subpop(analytic_pop_all) over(countrycat): proportion glp1_elig_Asia		
matrix est = e(b)'
putexcel F2 = matrix(est[101..200, 1]*100)										// --> Update according to # of countries

foreach x of num 1/100 {														// --> Update according to # of countries
sum year_num if countrycat == `x'
putexcel C`=1+`x'' = `r(mean)'
sum worldregion7 if countrycat == `x'
putexcel D`=1+`x'' = `r(mean)'
sum Population2020_age25to64 if countrycat == `x'
putexcel E`=1+`x'' = (`r(mean)'/1000)
}
tab country																		// --> Paste to B2


*** FIGURE 4: Wealth by country-income group ***

use "$data/glp1_final.dta", clear
cd "$data"
putexcel set Fig4_wealth.xlsx, sheet(wpop) replace

recode wealth_quintile (1=5) (2=4) (3=3) (4=2) (5=1), generate(wealth_quintile_rev)
label define wlth_rv 1 "Q5" 2 "Q4" 3 "Q3" 4 "Q2" 5 "Q1"
label values wealth_quintile_rev wlth_rv

svyset psu_num[pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  	

local i=-4
foreach x of num 1/4 {
local i=`i'+4
svy, subpop(analytic_pop_all if countryGDPclass == `x') over(wealth_quintile_rev): proportion glp1_elig_Asia
matrix est = e(b)'
putexcel D`=1+`x'+`i'' = matrix(est[6..10, 1]*100)
matrix ci = r(table)'
putexcel E`=1+`x'+`i'' = matrix(ci[6..10, 5..6]*100)
}


** TABLES 1 & S5 & S12: Absolute estimates **			

use "$data/glp1_final.dta", clear									
cd "$data"
putexcel set Tables1+S5_abs.xlsx, sheet(wpop) replace

svy, subpop(analytic_pop_all) over(countrycat): proportion glp1_elig_Asia		
matrix est = e(b)'
putexcel C4 = matrix(est[101..200, 1])										// --> Update according to # of countries
matrix ci = r(table)'
putexcel D4 = matrix(ci[101..200, 5..6])
foreach x of num 1/100 {
sum Population2020_age25to64 if countrycat == `x'
putexcel F`=3+`x'' = `r(mean)'
putexcel I`=3+`x'' = formula(C`=3+`x''*F`=3+`x'')
putexcel L`=3+`x'' = formula(D`=3+`x''*F`=3+`x'')
putexcel M`=3+`x'' = formula(E`=3+`x''*F`=3+`x'')
}
tab country																		// --> Paste to B4

svyset [pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  	// Drop PSU for countries with single PSU (same point estimate, but with CIs)

tab countrycat if country == "Czech Republic" | country == "Kuwait" | country == "Malta" | country == "Marshall Islands" ///
| country == "Niue" | country == "Romania" | country == "Seychelles" | country == "Uruguay"

foreach x of num 22 42 50 51 62 70 75 94 {											// --> Update numbers !!!!
svy, subpop(analytic_pop_all if countrycat == `x'): proportion glp1_elig_Asia
matrix ci = r(table)'
putexcel D`=3+`x'' = matrix(ci[2, 5..6]*100)
}

/* * Number of adults 25-64 in 100 countries by country-income group
use "$data/glp1_final.dta", clear									
collapse Population2020_age25to64 countryGDP, by(country)
forvalues x = 1/4 {
sum Population2020_age25to64 if countryGDP == `x'
display `r(sum)'
} 

*/



********************************************************************************
***							 PAPER TEXT										 ***						
********************************************************************************



********************************************************************************
***							 APPENDIX										 ***						
********************************************************************************

*** TABLE S6: Missingness by country ***	

use "$data/glp1_full.dta", clear		
cd "$data"
putexcel set TableS6_Missing.xlsx, replace

drop if mi(age) | mi(sex)																
drop if age <25 | (age >64 & !mi(age))					
drop if pregnant == 1 									
drop if mi(path_bio) | w3 == 0	
count												// N2 = 832,026

foreach x of num 1/100 {
count if countrycat == `x'
global A = `r(N)'
drop if (mi(bmi) | mi(sbp_avg_new) | mi(dbp_avg_new) | mi(clin_dia_fx) | mi(hypt_new) | mi(clin_hypt_fx)) & countrycat == `x'	
putexcel C`=4+`x'' = `r(N_drop)'
putexcel D`=4+`x'' = `r(N_drop)'/$A , nformat("0.0%")

count if countrycat == `x'
global B = `r(N)'
drop if mi(psu_num)	& countrycat == `x'			
putexcel E`=4+`x'' = `r(N_drop)'
putexcel F`=4+`x'' = `r(N_drop)'/$B , nformat("0.0%")

macro drop A B
}

use "$data/glp1_full.dta", clear		
drop if mi(age) | mi(sex)																
drop if age <25 | (age >64 & !mi(age))					
drop if pregnant == 1 									
drop if mi(path_bio) | w3 == 0	

foreach x of num 1/100 {
drop if (mi(bmi) | mi(sbp_avg_new) | mi(dbp_avg_new) | mi(clin_dia_fx) | mi(hypt_new) | mi(clin_hypt_fx)) & countrycat == `x'	
drop if mi(psu_num)	& countrycat == `x'	
		
count if countrycat == `x'
global C = `r(N)'

drop if mi(educat3)	& countrycat == `x'	
putexcel G`=4+`x'' = `r(N_drop)'
putexcel H`=4+`x'' = `r(N_drop)'/$C , nformat("0.0%")

macro drop C
}

use "$data/glp1_full.dta", clear		
drop if mi(age) | mi(sex)																
drop if age <25 | (age >64 & !mi(age))					
drop if pregnant == 1 									
drop if mi(path_bio) | w3 == 0	

foreach x of num 1/100 {
drop if (mi(bmi) | mi(sbp_avg_new) | mi(dbp_avg_new) | mi(clin_dia_fx) | mi(hypt_new) | mi(clin_hypt_fx)) & countrycat == `x'	
drop if mi(psu_num)	& countrycat == `x'	

count if countrycat == `x'
global D = `r(N)'

drop if mi(wealth_quintile)	& countrycat == `x'				
putexcel I`=4+`x'' = `r(N_drop)'
putexcel J`=4+`x'' = `r(N_drop)'/$D , nformat("0.0%")	

macro drop D
}


*** TABLE S4: Survey characteristics ***				

use "$data/glp1_final.dta", clear

collapse countryGDPclass worldregion7, by(country) 	// Copy from data browser for exel
label define GDP_short 1 "LIC" 2 "Lower-MIC" 3 "Upper-MIC" 4 "HIC"
label values countryGDPclass GDP_short
label values worldregion7 wr7   

* Country estimates *			

use "$data/glp1_final.dta", clear
cd "$data"
putexcel set tableS4_svychar.xlsx, modify

*tab country 	// Verify that same order
*collapse countrycat, by(country)

forval x = 1/100 {
preserve
keep if countrycat == `x'	
putexcel D`=3+`x'' = year[1]
putexcel G`=3+`x'' = RR_Type[1]
restore
sum response_rate if countrycat == `x', detail
putexcel F`=3+`x'' = matrix(r(p50)), nformat("0.0%") 
count if countrycat == `x' & analytic_pop_all == 1 
putexcel H`=3+`x'' = `r(N)'
sum age if analytic_pop_all == 1 & countrycat == `x'
putexcel I`=3+`x'' = `r(min)'
putexcel J`=3+`x'' = `r(max)'
sum age if countrycat == `x' & analytic_pop_all == 1, detail
putexcel K`=3+`x'' = matrix(r(p50)), nformat("0.0") 
count if countrycat == `x' & analytic_pop_all == 1 & sex == 1
putexcel M`=3+`x'' = `r(N)'
svy, subpop(analytic_pop_all): proportion sex if countrycat == `x'
matrix est = e(b)'
matrix sx = matrix(est[2..2, 1])
putexcel N`=3+`x'' = matrix(sx), nformat("0.0%") 
}

* Global estimates *								

count if analytic_pop_all == 1 
putexcel H107 = `r(N)'
sum age if analytic_pop_all == 1, detail
putexcel K107 = matrix(r(p50)), nformat("0.0") 
sum age if analytic_pop_all == 1 
putexcel I107 = `r(min)'
putexcel J107 = `r(max)'
count if analytic_pop_all == 1 & sex == 1
putexcel M107 = `r(N)'
svy, subpop(analytic_pop_all): proportion sex 
matrix est = e(b)'
matrix sx = matrix(est[2..2, 1])
putexcel N107 = matrix(sx), nformat("0.0%") 

* Median response rate global 						// Note: No response rate reported for Indonesia, Kazhakstan, Malawi, Palestine, Romania so not included in calculation
collapse response_rate, by(country) 
drop if mi(response_rate)
count
sum response_rate, detail							// also indicates IQR
putexcel F107 = matrix(r(p50)), nformat("0.0%") 


*** TABLE S5: Disease prevalence ***			

use "$data/glp1_final.dta", clear

collapse countryGDPclass worldregion7, by(country) 	// Copy from data browser for exel
label define GDP_short 1 "LIC" 2 "Lower-MIC" 3 "Upper-MIC" 4 "HIC"
label values countryGDPclass GDP_short
label values worldregion7 wr7   

* Country estimates *			

use "$data/glp1_final.dta", clear
cd "$data"
putexcel set tableS5_prev.xlsx, modify

*tab country 	// Verify that same order
*collapse countrycat, by(country)

svy, subpop(analytic_pop_all) over(countrycat): proportion obese_Asia		
matrix est = e(b)'
putexcel C6 = matrix(est[101..200, 1]), nformat("0.0%")							// --> Update according to # of countries
matrix ci = r(table)'
putexcel D6 = matrix(ci[101..200, 5..6]*100), nformat("0.0")

svy, subpop(analytic_pop_all) over(countrycat): proportion clin_hypt_fx		
matrix est = e(b)'
putexcel F6 = matrix(est[101..200, 1]), nformat("0.0%")							// --> Update according to # of countries
matrix ci = r(table)'
putexcel G6 = matrix(ci[101..200, 5..6]*100), nformat("0.0")

svy, subpop(analytic_pop_all) over(countrycat): proportion clin_dia_fx		
matrix est = e(b)'
putexcel I6 = matrix(est[101..200, 1]), nformat("0.0%")							// --> Update according to # of countries
matrix ci = r(table)'
putexcel J6 = matrix(ci[101..200, 5..6]*100), nformat("0.0")

* FIX CIs of individual countries

svyset [pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  	// Drop PSU for countries with single PSU (same point estimate, but with CIs)

tab countrycat if country == "Czech Republic" | country == "Kuwait" | country == "Malta" | country == "Marshall Islands" ///
| country == "Niue" | country == "Romania" | country == "Seychelles" | country == "Uruguay"

foreach x of num 22 42 50 51 62 70 75 94 {											// --> Update numbers !!!!
svy, subpop(analytic_pop_all if countrycat == `x'): proportion obese_Asia		
matrix ci = r(table)'
putexcel D`=5+`x'' = matrix(ci[2, 5..6]*100)

svy, subpop(analytic_pop_all if countrycat == `x'): proportion clin_hypt_fx	
matrix ci = r(table)'
putexcel G`=5+`x'' = matrix(ci[2, 5..6]*100)
	
svy, subpop(analytic_pop_all if countrycat == `x'): proportion clin_dia_fx		
matrix ci = r(table)'
putexcel J`=5+`x'' = matrix(ci[2, 5..6]*100)
}

* Global estimates *								

svy, subpop(analytic_pop_all): proportion obese_Asia	
matrix est = e(b)'
putexcel C107 = matrix(est[2..2, 1]), nformat("0.0%") 								
matrix ci = r(table)'
putexcel D107 = matrix(ci[2..2, 5..6]*100), nformat("0.0")

svy, subpop(analytic_pop_all): proportion clin_hypt_fx	
matrix est = e(b)'
putexcel F107 = matrix(est[2..2, 1]), nformat("0.0%") 								
matrix ci = r(table)'
putexcel G107 = matrix(ci[2..2, 5..6]*100), nformat("0.0")

svy, subpop(analytic_pop_all): proportion clin_dia_fx	
matrix est = e(b)'
putexcel I107 = matrix(est[2..2, 1]), nformat("0.0%") 								
matrix ci = r(table)'
putexcel J107 = matrix(ci[2..2, 5..6]*100), nformat("0.0")


*** TABLE S8: Participant characteristics ***												

use "$data/glp1_final.dta", clear
cd "$data"

svyset psu_num[pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  	
putexcel set FigS8_indchar.xlsx, sheet(Table 1) modify

** Sex **	
count if analytic_pop_all == 1 & !mi(sex)
putexcel D4 = `r(N)'
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & !mi(sex)		
putexcel H4 = `r(N)'	
foreach x of num 0/1 {
tab sex if sex == `x' & analytic_pop_all == 1
putexcel D`=5+`x'' = `r(N)'
tab sex if sex == `x' & analytic_pop_all == 1 & glp1_elig_Asia == 1
putexcel H`=5+`x'' = `r(N)'
}
svy, subpop(analytic_pop_all): proportion sex
matrix results_all = e(b)'
putexcel E5 = matrix(results_all), nformat("0.0%")
matrix ci = r(table)'
putexcel F5 = matrix(ci[1..2, 5..6]*100)

svy, subpop(analytic_pop_all if glp1_elig_Asia == 1): proportion sex
matrix results_elig = e(b)'	
putexcel I5 = matrix(results_elig), nformat("0.0%")
matrix ci = r(table)'
putexcel J5 = matrix(ci[1..2, 5..6]*100)

** Age **
count if analytic_pop_all == 1 & !mi(age_cat)
putexcel D7 = `r(N)'
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & !mi(age_cat)		
putexcel H7 = `r(N)'	
foreach x of num 1/4 {
tab age_cat if age_cat == `x' & analytic_pop_all == 1
putexcel D`=7+`x'' = `r(N)'
tab age_cat if age_cat == `x' & analytic_pop_all == 1 & glp1_elig_Asia == 1
putexcel H`=7+`x'' = `r(N)'
}
svy, subpop(analytic_pop_all): proportion age_cat
matrix results_all = e(b)'
putexcel E8 = matrix(results_all), nformat("0.0%")
matrix ci = r(table)'
putexcel F8 = matrix(ci[1..4, 5..6]*100)
svy, subpop(analytic_pop_all if glp1_elig_Asia == 1): proportion age_cat
matrix results_elig = e(b)'	
putexcel I8 = matrix(results_elig), nformat("0.0%")
matrix ci = r(table)'
putexcel J8 = matrix(ci[1..4, 5..6]*100)

** Education **
count if analytic_pop_all == 1 & !mi(educat3)
putexcel D12 = `r(N)'
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & !mi(educat3)		
putexcel H12 = `r(N)'	
foreach x of num 0/2 {
tab educat3 if educat3 == `x' & analytic_pop_all == 1
putexcel D`=13+`x'' = `r(N)'
tab educat3 if educat3 == `x' & analytic_pop_all == 1 & glp1_elig_Asia == 1
putexcel H`=13+`x'' = `r(N)'
}
svy, subpop(analytic_pop_all): proportion educat3
matrix results_all = e(b)'
putexcel E13 = matrix(results_all), nformat("0.0%")
matrix ci = r(table)'
putexcel F13 = matrix(ci[1..3, 5..6]*100)
svy, subpop(analytic_pop_all if glp1_elig_Asia == 1): proportion educat3
matrix results_elig = e(b)'	
putexcel I13 = matrix(results_elig), nformat("0.0%")
matrix ci = r(table)'
putexcel J13 = matrix(ci[1..3, 5..6]*100)

** Wealth **
count if analytic_pop_all == 1 & !mi(wealth_quintile)
putexcel D16 = `r(N)'
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & !mi(wealth_quintile)		
putexcel H16 = `r(N)'	
foreach x of num 1/5 {
tab wealth_quintile if wealth_quintile == `x' & analytic_pop_all == 1
putexcel D`=16+`x'' = `r(N)'
tab wealth_quintile if wealth_quintile == `x' & analytic_pop_all == 1 & glp1_elig_Asia == 1
putexcel H`=16+`x'' = `r(N)'
}
svy, subpop(analytic_pop_all): proportion wealth_quintile
matrix results_all = e(b)'
putexcel E17 = matrix(results_all), nformat("0.0%")
matrix ci = r(table)'
putexcel F17 = matrix(ci[1..5, 5..6]*100)
svy, subpop(analytic_pop_all if glp1_elig_Asia == 1): proportion wealth_quintile
matrix results_elig = e(b)'	
putexcel I17 = matrix(results_elig), nformat("0.0%")
matrix ci = r(table)'
putexcel J17 = matrix(ci[1..5, 5..6]*100)


*** TABLE S9: Country estimates for bubble plot ***

use "$data/glp1_final.dta", clear									
cd "$data"

merge m:1 country using "/Users/felixteufel/Library/CloudStorage/OneDrive-Emory/DESKTOP/GLP-1 eligibility/Data/GNI/GNI_R_export.dta" // Merge GNI from R export
drop _merge				// all merged
		  
putexcel set TablesS9_rel.xlsx, sheet(wpop) replace
		 
svy, subpop(analytic_pop_all) over(countrycat): proportion glp1_elig_Asia		
matrix est = e(b)'
putexcel C4 = matrix(est[101..200, 1]*100)										// --> Update according to # of countries
matrix ci = r(table)'
putexcel D4 = matrix(ci[101..200, 5..6]*100)
foreach x of num 1/100 {
sum Population2020_age25to64 if countrycat == `x'
matrix est = r(mean)*1000
putexcel J`=3+`x'' = matrix(est)
sum income if countrycat == `x'
putexcel K`=3+`x'' = `r(mean)'
}
tab country																		// --> Paste to B4 and G4

svyset [pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  	// Drop PSU for countries with single PSU (same point estimate, but with CIs)

tab countrycat if country == "Czech Republic" | country == "Kuwait" | country == "Malta" | country == "Marshall Islands" ///
| country == "Niue" | country == "Romania" | country == "Seychelles" | country == "Uruguay"

foreach x of num 22 42 50 51 62 70 75 94 {											// --> Update numbers !!!!
svy, subpop(analytic_pop_all if countrycat == `x'): proportion glp1_elig_Asia
matrix ci = r(table)'
putexcel D`=3+`x'' = matrix(ci[2, 5..6]*100)
}

*** Table S14: Wealth by country-income group ***		// Note: Same data as Figure 3 but reverse order of quintiles

use "$data/glp1_final.dta", clear
cd "$data"
putexcel set TableS14_wealth.xlsx, sheet(wpop) replace

svyset psu_num[pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  	

local i=-4
foreach x of num 1/4 {
local i=`i'+4
svy, subpop(analytic_pop_all if countryGDPclass == `x') over(wealth_quintile): proportion glp1_elig_Asia
matrix est = e(b)'
putexcel D`=1+`x'+`i'' = matrix(est[6..10, 1]*100)
matrix ci = r(table)'
putexcel E`=1+`x'+`i'' = matrix(ci[6..10, 5..6]*100)
}


*** FIGURE S1: Equiplot ***

use "$data/glp1_final.dta", clear
cd "$data"
putexcel set FigureS1_equiplot.xlsx, sheet(wpop) replace

svyset psu_num[pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  		
drop if mi(wealth_quintile) 
*codebook country																// N1 = 78 surveys (77 countries)
	
svy, subpop(analytic_pop_all if wealth_quintile == 1) over(countrycat): proportion glp1_elig_Asia 
matrix est1 = e(b)'
putexcel B2 = matrix(est1[79..156, 1]*100)										// --> Update according to # of countries
svy, subpop(analytic_pop_all if wealth_quintile == 5) over(countrycat): proportion glp1_elig_Asia 
matrix est2 = e(b)'
putexcel C2 = matrix(est2[79..156, 1]*100)										// --> Update according to # of countries
drop countrycat
egen countrycat = group(country)
foreach x of num 1/78 {															// --> Update according to N1
sum countryGDPclass if countrycat == `x'
capture putexcel D`=1+`x'' = `r(mean)'
}
tab country																		// --> Paste to A2											


*** FIGURE S2: Share identified due to comorbidity and not BMI ≥30 (28) 

use "$data/glp1_final.dta", clear
cd "$data"
putexcel set FigureS2_comorb.xlsx, sheet(wpop) replace

/*
tab glp1_elig_Asia obese_Asia if analytic_pop_all == 1 							// All people with obesity are GLP-1 eligible, but not all people eligible for GLP-1 are obese
tab glp1_comorb if analytic_pop_all == 1 

svy, subpop(analytic_pop_all): proportion glp1_elig_Asia						// 25.22082%
svy, subpop(analytic_pop_all): proportion obese_Asia							// 17.23519%
dis 1-(17.23519/25.22082)														// 31.66285%
svy, subpop(analytic_pop_all): proportion glp1_comorb							// 31.66286%
*/

svy, subpop(analytic_pop_all): proportion glp1_comorb
matrix est = e(b)'
putexcel B102 = matrix(est[2..2, 1]*100)										// --> Update according to # of countries
matrix ci = r(table)'
putexcel C102 = matrix(ci[2..2, 5..6]*100)
putexcel E102 = 8

svy, subpop(analytic_pop_all) over(countrycat): proportion glp1_comorb
matrix est = e(b)'
putexcel B2 = matrix(est[101..200, 1]*100)										// --> Update according to # of countries
matrix ci = r(table)'
putexcel C2 = matrix(ci[101..200, 5..6]*100)
foreach x of num 1/100 {															// --> Update according to # of countries
sum worldregion7 if countrycat == `x'
capture putexcel E`=1+`x'' = `r(mean)'
}
tab country																		// --> Paste to A2

svyset [pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  	// Drop PSU for countries with single PSU (same point estimate, but with CIs)

tab countrycat if country == "Czech Republic" | country == "Kuwait" | country == "Malta" | country == "Marshall Islands" ///
| country == "Niue" | country == "Romania" | country == "Seychelles" | country == "Uruguay"

foreach x of num 22 42 50 51 62 70 75 94 {											// --> Update numbers !!!!
svy, subpop(analytic_pop_all if countrycat == `x'): proportion glp1_comorb
matrix ci = r(table)'
putexcel C`=1+`x'' = matrix(ci[2, 5..6]*100)
}


*** TABLE S11: Age standardized results ***

** Eligibility by country-level characteristics **		

use "$data/glp1_final.dta", clear
cd "$data"

svyset psu_num[pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  		
putexcel set Table_S11_agestd.xlsx, sheet(Countries) modify

* Global *
svy, subpop(analytic_pop_all): proportion glp1_elig_Asia, stdize(agecat_std) stdweight(std_wt)
matrix est = e(b)
putexcel E2 = matrix(est[1, 2]*100)
matrix ci = r(table)'
putexcel F2 = matrix(ci[2, 5..6]*100)
count if analytic_pop_all == 1 & glp1_elig_Asia == 1
putexcel C2 = `r(N)'
count if analytic_pop_all == 1
putexcel D2 = `r(N)'

* Country-income group *
svy, subpop(analytic_pop_all) over(countryGDPclass): proportion glp1_elig_Asia, stdize(agecat_std) stdweight(std_wt)
matrix est = e(b)'
putexcel E4 = matrix(est[5..8, 1]*100)
matrix ci = r(table)'
putexcel F4 = matrix(ci[5..8, 5..6]*100)
forval x = 1/4 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & countryGDPclass == `x'
putexcel C`=3+`x'' = `r(N)'
count if analytic_pop_all == 1 & countryGDPclass == `x'
putexcel D`=3+`x'' = `r(N)'
}

* Region *
svy, subpop(analytic_pop_all) over(worldregion7): proportion glp1_elig_Asia, stdize(agecat_std) stdweight(std_wt)
matrix est = e(b)'
putexcel E9 = matrix(est[8..14, 1]*100)
matrix ci = r(table)'
putexcel F9 = matrix(ci[8..14, 5..6]*100)
forval x = 1/7 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & worldregion7 == `x'
putexcel C`=8+`x'' = `r(N)'
count if analytic_pop_all == 1 & worldregion7 == `x'
putexcel D`=8+`x'' = `r(N)'
}

** Eligibility by individual-level characteristics **		

use "$data/glp1_final.dta", clear
svyset psu_num[pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  		
putexcel set Table_S11_agestd.xlsx, sheet(Individuals) modify

* Sex *			
svy, subpop(analytic_pop_all) over(sex): proportion glp1_elig_Asia, stdize(agecat_std) stdweight(std_wt)
matrix est = e(b)'
putexcel E3 = matrix(est[3..4, 1]*100)
matrix ci = r(table)'
putexcel F3 = matrix(ci[3..4, 5..6]*100)
forval x = 0/1 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & sex == `x'
putexcel C`=3+`x'' = `r(N)'
count if analytic_pop_all == 1 & sex == `x'
putexcel D`=3+`x'' = `r(N)'
}

* Age group *
preserve
drop if mi(age) & analytic_pop_all == 1					
svy, subpop(analytic_pop_all) over(age_cat): proportion glp1_elig_Asia, stdize(agecat_std) stdweight(std_wt)
matrix est = e(b)'
putexcel E6 = matrix(est[5..8, 1]*100)
matrix ci = r(table)'
putexcel F6 = matrix(ci[5..8, 5..6]*100)
forval x = 1/4 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & age_cat == `x'
putexcel C`=5+`x'' = `r(N)'
count if analytic_pop_all == 1 & age_cat == `x'
putexcel D`=5+`x'' = `r(N)'
}
restore 

* Education *
preserve
drop if country == "Tokelau"									
drop if mi(educat3) & analytic_pop_all == 1						
svy, subpop(analytic_pop_all) over(educat3): proportion glp1_elig_Asia, stdize(agecat_std) stdweight(std_wt)
matrix est = e(b)'
putexcel E11 = matrix(est[4..6, 1]*100)
matrix ci = r(table)'
putexcel F11 = matrix(ci[4..6, 5..6]*100)
forval x = 0/2 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & educat3 == `x'
putexcel C`=11+`x'' = `r(N)'
count if analytic_pop_all == 1 & educat3 == `x'
putexcel D`=11+`x'' = `r(N)'
}
restore

* Wealth quintiles *																		
preserve
drop if country == "Bangladesh" | country == "Barbados" | country == "Belarus" | country == "Burkina Faso" | country == "Costa Rica" ///
| country == "Czech Republic" | country == "El Salvador" | country == "England" | country == "Iraq" | country == "Libya" ///
| country == "Malawi" | country == "Malta" | country == "Nepal" | country == "Nigeria" | country == "Pakistan" ///
| country == "Qatar" | country == "Spain" | country == "Tokelau" | country == "Turkmenistan" | country == "USA"  ///
| country == "Venezuela" | country == "Wallis and Futuna"
drop if mi(wealth_quintile) & analytic_pop_all == 1	
svy, subpop(analytic_pop_all) over(wealth_quintile): proportion glp1_elig_Asia, stdize(agecat_std) stdweight(std_wt)
matrix est = e(b)'
putexcel E15 = matrix(est[6..10, 1]*100)
matrix ci = r(table)'
putexcel F15 = matrix(ci[6..10, 5..6]*100)
forval x = 1/5 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & wealth_quintile == `x'
putexcel C`=14+`x'' = `r(N)'
count if analytic_pop_all == 1 & wealth_quintile == `x'
putexcel D`=14+`x'' = `r(N)'
}
restore


**** SA: USING NON-ASIAN CUT-OFFS **** 

*** TABLE S12: Main results ***

** Eligibility by country-level characteristics **		

use "$data/glp1_final.dta", clear
cd "$data"

svyset psu_num[pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  		
putexcel set Table_S12_main_noAS.xlsx, sheet(Countries) modify

* Global *
svy, subpop(analytic_pop_all): proportion glp1_elig_noAs
matrix est = e(b)
putexcel E2 = matrix(est[1, 2]*100)
matrix ci = r(table)'
putexcel F2 = matrix(ci[2, 5..6]*100)
count if analytic_pop_all == 1 & glp1_elig_noAs == 1
putexcel C2 = `r(N)'
count if analytic_pop_all == 1
putexcel D2 = `r(N)'

* Country-income group *
svy, subpop(analytic_pop_all) over(countryGDPclass): proportion glp1_elig_noAs
matrix est = e(b)'
putexcel E4 = matrix(est[5..8, 1]*100)
matrix ci = r(table)'
putexcel F4 = matrix(ci[5..8, 5..6]*100)
forval x = 1/4 {
count if analytic_pop_all == 1 & glp1_elig_noAs == 1 & countryGDPclass == `x'
putexcel C`=3+`x'' = `r(N)'
count if analytic_pop_all == 1 & countryGDPclass == `x'
putexcel D`=3+`x'' = `r(N)'
}

* Region *
svy, subpop(analytic_pop_all) over(worldregion7): proportion glp1_elig_noAs
matrix est = e(b)'
putexcel E9 = matrix(est[8..14, 1]*100)
matrix ci = r(table)'
putexcel F9 = matrix(ci[8..14, 5..6]*100)
forval x = 1/7 {
count if analytic_pop_all == 1 & glp1_elig_noAs == 1 & worldregion7 == `x'
putexcel C`=8+`x'' = `r(N)'
count if analytic_pop_all == 1 & worldregion7 == `x'
putexcel D`=8+`x'' = `r(N)'
}

** Eligibility by individual-level characteristics **		

use "$data/glp1_final.dta", clear
svyset psu_num[pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  		
putexcel set Table_S12_main_noAS.xlsx, sheet(Individuals) modify

* Sex *			
svy, subpop(analytic_pop_all) over(sex): proportion glp1_elig_noAs
matrix est = e(b)'
putexcel E3 = matrix(est[3..4, 1]*100)
matrix ci = r(table)'
putexcel F3 = matrix(ci[3..4, 5..6]*100)
forval x = 0/1 {
count if analytic_pop_all == 1 & glp1_elig_noAs == 1 & sex == `x'
putexcel C`=3+`x'' = `r(N)'
count if analytic_pop_all == 1 & sex == `x'
putexcel D`=3+`x'' = `r(N)'
}

* Age group *
preserve
drop if mi(age) & analytic_pop_all == 1					
svy, subpop(analytic_pop_all) over(age_cat): proportion glp1_elig_noAs
matrix est = e(b)'
putexcel E6 = matrix(est[5..8, 1]*100)
matrix ci = r(table)'
putexcel F6 = matrix(ci[5..8, 5..6]*100)
forval x = 1/4 {
count if analytic_pop_all == 1 & glp1_elig_noAs == 1 & age_cat == `x'
putexcel C`=5+`x'' = `r(N)'
count if analytic_pop_all == 1 & age_cat == `x'
putexcel D`=5+`x'' = `r(N)'
}
restore 

* Education *
preserve
drop if country == "Tokelau"								
drop if mi(educat3) & analytic_pop_all == 1						
svy, subpop(analytic_pop_all) over(educat3): proportion glp1_elig_noAs
matrix est = e(b)'
putexcel E11 = matrix(est[4..6, 1]*100)
matrix ci = r(table)'
putexcel F11 = matrix(ci[4..6, 5..6]*100)
forval x = 0/2 {
count if analytic_pop_all == 1 & glp1_elig_noAs == 1 & educat3 == `x'
putexcel C`=11+`x'' = `r(N)'
count if analytic_pop_all == 1 & educat3 == `x'
putexcel D`=11+`x'' = `r(N)'
}
restore

* Wealth quintiles *																		
preserve
drop if country == "Bangladesh" | country == "Barbados" | country == "Belarus" | country == "Burkina Faso" | country == "Costa Rica" ///
| country == "Czech Republic" | country == "El Salvador" | country == "England" | country == "Iraq" | country == "Libya" ///
| country == "Malawi" | country == "Malta" | country == "Nepal" | country == "Nigeria" | country == "Pakistan" ///
| country == "Qatar" | country == "Spain" | country == "Tokelau" | country == "Turkmenistan" | country == "USA"  ///
| country == "Venezuela" | country == "Wallis and Futuna"
drop if mi(wealth_quintile) & analytic_pop_all == 1	
svy, subpop(analytic_pop_all) over(wealth_quintile): proportion glp1_elig_noAs
matrix est = e(b)'
putexcel E15 = matrix(est[6..10, 1]*100)
matrix ci = r(table)'
putexcel F15 = matrix(ci[6..10, 5..6]*100)
forval x = 1/5 {
count if analytic_pop_all == 1 & glp1_elig_noAs == 1 & wealth_quintile == `x'
putexcel C`=14+`x'' = `r(N)'
count if analytic_pop_all == 1 & wealth_quintile == `x'
putexcel D`=14+`x'' = `r(N)'
}
restore


**** SA: USING WEQ **** 

*** TABLE S13: Main results ***

use "$data/glp1_final.dta", clear
cd "$data"

svyset psu_num[pw = weq_w3_analytic], strata(stratum_num) singleunit(centered)  		
putexcel set Table_S13_main_weq.xlsx, sheet(Countries) modify

* Global *
svy, subpop(analytic_pop_all): proportion glp1_elig_Asia
matrix est = e(b)
putexcel E2 = matrix(est[1, 2]*100)
matrix ci = r(table)'
putexcel F2 = matrix(ci[2, 5..6]*100)
count if analytic_pop_all == 1 & glp1_elig_Asia == 1
putexcel C2 = `r(N)'
count if analytic_pop_all == 1
putexcel D2 = `r(N)'

* Country-income group *
svy, subpop(analytic_pop_all) over(countryGDPclass): proportion glp1_elig_Asia
matrix est = e(b)'
putexcel E4 = matrix(est[5..8, 1]*100)
matrix ci = r(table)'
putexcel F4 = matrix(ci[5..8, 5..6]*100)
forval x = 1/4 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & countryGDPclass == `x'
putexcel C`=3+`x'' = `r(N)'
count if analytic_pop_all == 1 & countryGDPclass == `x'
putexcel D`=3+`x'' = `r(N)'
}

* Region *
svy, subpop(analytic_pop_all) over(worldregion7): proportion glp1_elig_Asia
matrix est = e(b)'
putexcel E9 = matrix(est[8..14, 1]*100)
matrix ci = r(table)'
putexcel F9 = matrix(ci[8..14, 5..6]*100)
forval x = 1/7 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & worldregion7 == `x'
putexcel C`=8+`x'' = `r(N)'
count if analytic_pop_all == 1 & worldregion7 == `x'
putexcel D`=8+`x'' = `r(N)'
}

** Eligibility by individual-level characteristics **		

use "$data/glp1_final.dta", clear
svyset psu_num[pw = weq_w3_analytic], strata(stratum_num) singleunit(centered)  		
putexcel set Table_S13_main_weq.xlsx, sheet(Individuals) modify

* Sex *			
svy, subpop(analytic_pop_all) over(sex): proportion glp1_elig_Asia
matrix est = e(b)'
putexcel E3 = matrix(est[3..4, 1]*100)
matrix ci = r(table)'
putexcel F3 = matrix(ci[3..4, 5..6]*100)
forval x = 0/1 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & sex == `x'
putexcel C`=3+`x'' = `r(N)'
count if analytic_pop_all == 1 & sex == `x'
putexcel D`=3+`x'' = `r(N)'
}

* Age group *
preserve
drop if mi(age) & analytic_pop_all == 1					
svy, subpop(analytic_pop_all) over(age_cat): proportion glp1_elig_Asia
matrix est = e(b)'
putexcel E6 = matrix(est[5..8, 1]*100)
matrix ci = r(table)'
putexcel F6 = matrix(ci[5..8, 5..6]*100)
forval x = 1/4 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & age_cat == `x'
putexcel C`=5+`x'' = `r(N)'
count if analytic_pop_all == 1 & age_cat == `x'
putexcel D`=5+`x'' = `r(N)'
}
restore 

* Education *
preserve
drop if country == "Tokelau"									
drop if mi(educat3) & analytic_pop_all == 1						
svy, subpop(analytic_pop_all) over(educat3): proportion glp1_elig_Asia
matrix est = e(b)'
putexcel E11 = matrix(est[4..6, 1]*100)
matrix ci = r(table)'
putexcel F11 = matrix(ci[4..6, 5..6]*100)
forval x = 0/2 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & educat3 == `x'
putexcel C`=11+`x'' = `r(N)'
count if analytic_pop_all == 1 & educat3 == `x'
putexcel D`=11+`x'' = `r(N)'
}
restore

* Wealth quintiles *																		
preserve
drop if country == "Bangladesh" | country == "Barbados" | country == "Belarus" | country == "Burkina Faso" | country == "Costa Rica" ///
| country == "Czech Republic" | country == "El Salvador" | country == "England" | country == "Iraq" | country == "Libya" ///
| country == "Malawi" | country == "Malta" | country == "Nepal" | country == "Nigeria" | country == "Pakistan" ///
| country == "Qatar" | country == "Spain" | country == "Tokelau" | country == "Turkmenistan" | country == "USA"  ///
| country == "Venezuela" | country == "Wallis and Futuna"
drop if mi(wealth_quintile) & analytic_pop_all == 1	
svy, subpop(analytic_pop_all) over(wealth_quintile): proportion glp1_elig_Asia
matrix est = e(b)'
putexcel E15 = matrix(est[6..10, 1]*100)
matrix ci = r(table)'
putexcel F15 = matrix(ci[6..10, 5..6]*100)
forval x = 1/5 {
count if analytic_pop_all == 1 & glp1_elig_Asia == 1 & wealth_quintile == `x'
putexcel C`=14+`x'' = `r(N)'
count if analytic_pop_all == 1 & wealth_quintile == `x'
putexcel D`=14+`x'' = `r(N)'
}
restore


**** SA: ADDING LASI & DIFFERENT DIABETES DEFINITION ****		 // Same sample (complete biomarker data); just appending LASI; still using w3, except w2 for LASI

*** TABLE S17: Main results ***		

** CLEAN **

use "$data/glp1_final.dta", clear
cd "$data"

* Append LASI & combine with NFHS-5 *
append using "$data/LASI_clean.dta"

drop if country == "India" & age >=45

/*replace country = "India" if country == "India LASI"

drop wpop_w3_analytic all_obs_strat

bys country agecat_std sex: egen double all_obs_strat = total(w3_analytic) if w3_analytic != .
generate wpop_w3_analytic =.
replace wpop_w3_analytic = w3_analytic*Population2020_strat/all_obs_strat*/ 		

* Rescale India weights so that they sum to respective share of population

sum w3_analytic if country == "India"	
replace w3_analytic = w3_analytic*0.626912365 /`r(sum)'	
sum w3_analytic if country == "India"	
display r(sum)									// Should be = 0.626912365 --> Verified

sum w3_analytic if country == "India LASI"	
replace w3_analytic = w3_analytic*0.373087635 /`r(sum)'	
sum w3_analytic if country == "India LASI"	
display r(sum)									// Should be = 0.373087635 --> Verified

replace country = "India" if country == "India LASI"

drop wpop_w3_analytic all_obs_strat

bys country agecat_std sex: egen double all_obs_strat = total(w3_analytic) if w3_analytic != .
generate wpop_w3_analytic =.
replace wpop_w3_analytic = w3_analytic*Population2020_strat/all_obs_strat

sum wpop_w3_analytic if country == "India"	
display r(sum)
tab Population2020_age25to64 if country == "India"		// Should be same number --> Verified

* Svy design *
svyset psu_num[pw = wpop_w3_analytic], strata(stratum_num) singleunit(centered)  		

* New GLP-1 variable
gen glp1_NEW = 0
replace glp1_NEW = 1 if bmi >= 30 & bmi !=. 
replace glp1_NEW = 1 if bmi >= 27 & bmi !=. & (hbg_new == 1 | clin_hypt_fx == 1)
replace glp1_NEW = . if mi(bmi) | mi(hbg_new) | mi(clin_hypt_fx)

replace glp1_NEW = 0 if worldregion7 == 6
replace glp1_NEW = 1 if bmi >= 28 & bmi !=. & worldregion7 == 6
replace glp1_NEW = 1 if bmi >= 24 & bmi !=. & (hbg_new == 1 | clin_hypt_fx == 1) & worldregion7 == 6
replace glp1_NEW = . if mi(bmi) | mi(hbg_new) | mi(clin_hypt_fx)

** ANALYSIS **

putexcel set Table_S17_main_LASI.xlsx, sheet(countries) replace

* Global *
svy, subpop(analytic_pop_all): proportion glp1_NEW
matrix est = e(b)
putexcel E2 = matrix(est[1, 2]*100)
matrix ci = r(table)'
putexcel F2 = matrix(ci[2, 5..6]*100)
count if analytic_pop_all == 1 & glp1_NEW == 1
putexcel C2 = `r(N)'
count if analytic_pop_all == 1
putexcel D2 = `r(N)'

* Country-income group *
svy, subpop(analytic_pop_all) over(countryGDPclass): proportion glp1_NEW
matrix est = e(b)'
putexcel E4 = matrix(est[5..8, 1]*100)
matrix ci = r(table)'
putexcel F4 = matrix(ci[5..8, 5..6]*100)
forval x = 1/4 {
count if analytic_pop_all == 1 & glp1_NEW == 1 & countryGDPclass == `x'
putexcel C`=3+`x'' = `r(N)'
count if analytic_pop_all == 1 & countryGDPclass == `x'
putexcel D`=3+`x'' = `r(N)'
}

* Region *
svy, subpop(analytic_pop_all) over(worldregion7): proportion glp1_NEW
matrix est = e(b)'
putexcel E9 = matrix(est[8..14, 1]*100)
matrix ci = r(table)'
putexcel F9 = matrix(ci[8..14, 5..6]*100)
forval x = 1/7 {
count if analytic_pop_all == 1 & glp1_NEW == 1 & worldregion7 == `x'
putexcel C`=8+`x'' = `r(N)'
count if analytic_pop_all == 1 & worldregion7 == `x'
putexcel D`=8+`x'' = `r(N)'
}

** Eligibility by individual-level characteristics **		

putexcel set Table_S17_main_LASI.xlsx, sheet(individuals) modify

* Sex *			
svy, subpop(analytic_pop_all) over(sex): proportion glp1_NEW
matrix est = e(b)'
putexcel E3 = matrix(est[3..4, 1]*100)
matrix ci = r(table)'
putexcel F3 = matrix(ci[3..4, 5..6]*100)
forval x = 0/1 {
count if analytic_pop_all == 1 & glp1_NEW == 1 & sex == `x'
putexcel C`=3+`x'' = `r(N)'
count if analytic_pop_all == 1 & sex == `x'
putexcel D`=3+`x'' = `r(N)'
}

* Age group *
preserve
drop if mi(age) & analytic_pop_all == 1					
svy, subpop(analytic_pop_all) over(age_cat): proportion glp1_NEW
matrix est = e(b)'
putexcel E6 = matrix(est[5..8, 1]*100)
matrix ci = r(table)'
putexcel F6 = matrix(ci[5..8, 5..6]*100)
forval x = 1/4 {
count if analytic_pop_all == 1 & glp1_NEW == 1 & age_cat == `x'
putexcel C`=5+`x'' = `r(N)'
count if analytic_pop_all == 1 & age_cat == `x'
putexcel D`=5+`x'' = `r(N)'
}
restore 

* Education *
preserve
drop if country == "Tokelau"									
drop if mi(educat3) & analytic_pop_all == 1						
svy, subpop(analytic_pop_all) over(educat3): proportion glp1_NEW
matrix est = e(b)'
putexcel E11 = matrix(est[4..6, 1]*100)
matrix ci = r(table)'
putexcel F11 = matrix(ci[4..6, 5..6]*100)
forval x = 0/2 {
count if analytic_pop_all == 1 & glp1_NEW == 1 & educat3 == `x'
putexcel C`=11+`x'' = `r(N)'
count if analytic_pop_all == 1 & educat3 == `x'
putexcel D`=11+`x'' = `r(N)'
}
restore

* Wealth quintiles *																		
preserve
drop if country == "Bangladesh" | country == "Barbados" | country == "Belarus" | country == "Burkina Faso" | country == "Costa Rica" ///
| country == "Czech Republic" | country == "El Salvador" | country == "England" | country == "Iraq" | country == "Libya" ///
| country == "Malawi" | country == "Malta" | country == "Nepal" | country == "Nigeria" | country == "Pakistan" ///
| country == "Qatar" | country == "Spain" | country == "Tokelau" | country == "Turkmenistan" | country == "USA"  ///
| country == "Venezuela" | country == "Wallis and Futuna"
drop if mi(wealth_quintile) & analytic_pop_all == 1	
svy, subpop(analytic_pop_all) over(wealth_quintile): proportion glp1_NEW
matrix est = e(b)'
putexcel E15 = matrix(est[6..10, 1]*100)
matrix ci = r(table)'
putexcel F15 = matrix(ci[6..10, 5..6]*100)
forval x = 1/5 {
count if analytic_pop_all == 1 & glp1_NEW == 1 & wealth_quintile == `x'
putexcel C`=14+`x'' = `r(N)'
count if analytic_pop_all == 1 & wealth_quintile == `x'
putexcel D`=14+`x'' = `r(N)'
}
restore

											
